#ifndef FTPINST_H
#define FTPINST_H

#include <QObject>
#include <QUrlInfo>
#include <QFile>
#include <QFtp>
#include <QUrl>
#include <QList>
#include <QTimer>
#include <QTreeWidget>
#include <QMessageBox>

#include "logindialog.h"
#include "settingsdialog.h"

class ftpInst : public QWidget
{
Q_OBJECT
public:
    explicit ftpInst(QWidget *parent = 0);
    ~ftpInst();

    void setParentTreeWidgetItem( QTreeWidgetItem * );
    void setClickedTreeWidgetItem( QTreeWidgetItem * );
    void setInputParameters( QString&, QString&, QString&, QString& );

    bool matchHost( const QString& );

    void settingsChanged();
    void proceedFolder();
    void connectFtp();
    void refresh();

    settingsDialog * mySettings;
    QTreeWidget * mainWidget;

signals:
    void commandError( QString, QString );
    void listDone();
    void refreshDone( int, int, int );

private slots:
    QString getFullUrlPath( QTreeWidgetItem * );
    QString getUrlAttr( const QUrlInfo & );
    int customColumnNumber( const QString&  );
    void drawTreeItem( QTreeWidgetItem *, bool, const QUrlInfo & );
    QString getConvertedSize( qint64 );
    void ftpCommandFinished(int, bool);
    void addToList( const QUrlInfo & );

    void updateTimer();

private:
    QFtp *ftp;
    QTreeWidgetItem * ftpParentItem;
    QTreeWidgetItem * clickedItem;
    QHash<QString, QUrlInfo> ftpItemsList;

    QTimer *queryTimer;
    QTime queryTime;

    QString hostname;
    QString username;
    QString password;
    QString remoteDir;

    int deleted;
    int modified;
    int added;

    bool isRefresh;
};

#endif // FTPINST_H
